#include "haed.h"


/* 客户端 */
int main()
{
	struct sockaddr_in soc;
	int fd = -1;
	//创建套接字
	if((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
	{
		perror("socket");
		exit(0);
	}

	/* 填充 struct sockaddr_in 结构体变量*/
	soc.sin_family = AF_INET;
	soc.sin_port = htons(SERV_PORT);
#if 0
	soc.sin_addr = inet_addr(SERV_IP_ADDR);
#else
	if((inet_pton(AF_INET, SERV_IP_ADDR, (void* )&soc.sin_addr)) != 1)
	{
		perror("inet_ntop");
		exit(0);
	}

#endif

	//连接服务器
	if((connect(fd, (struct sockaddr* )&soc, sizeof(soc))) < 0)
	{
		perror("connect");
		exit(0);
	}

	/* 读写 */
	char buf[BUFSI];
	int ret = -1;
	bzero(buf, BUFSI);
	while((fgets(buf, BUFSI-1, stdin)) == NULL)
	{
		continue;
	}	
	do
	{
			ret = write(fd, buf, strlen(buf));
	}while(ret < 0 && EINTR == errno );

	printf("read =%s", buf);


	//关闭套接字
	close(fd);


















}
